package com.ruoyi.project.beautyflower.userBankcard.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.beautyflower.userBankcard.domain.UserBankcard;
import com.ruoyi.project.beautyflower.userBankcard.service.IUserBankcardService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 用户绑定银行卡 信息操作处理
 * 
 * @author lxs
 * @date 2018-10-12
 */
@Controller
@RequestMapping("/beautyflower/userBankcard")
public class UserBankcardController extends BaseController
{
    private String prefix = "beautyflower/userBankcard";
	
	@Autowired
	private IUserBankcardService userBankcardService;
	
	@RequiresPermissions("beautyflower:userBankcard:view")
	@GetMapping()
	public String userBankcard()
	{
	    return prefix + "/userBankcard";
	}
	
	/**
	 * 查询用户绑定银行卡列表
	 */
	@RequiresPermissions("beautyflower:userBankcard:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserBankcard userBankcard)
	{
		startPage();
        List<UserBankcard> list = userBankcardService.selectUserBankcardList(userBankcard);
		return getDataTable(list);
	}
	
	/**
	 * 新增用户绑定银行卡
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户绑定银行卡
	 */
	@RequiresPermissions("beautyflower:userBankcard:add")
	@Log(title = "用户绑定银行卡", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserBankcard userBankcard)
	{		
		return toAjax(userBankcardService.insertUserBankcard(userBankcard));
	}

	/**
	 * 修改用户绑定银行卡
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		UserBankcard userBankcard = userBankcardService.selectUserBankcardById(id);
		mmap.put("userBankcard", userBankcard);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户绑定银行卡
	 */
	@RequiresPermissions("beautyflower:userBankcard:edit")
	@Log(title = "用户绑定银行卡", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserBankcard userBankcard)
	{		
		return toAjax(userBankcardService.updateUserBankcard(userBankcard));
	}
	
	/**
	 * 删除用户绑定银行卡
	 */
	@RequiresPermissions("beautyflower:userBankcard:remove")
	@Log(title = "用户绑定银行卡", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(userBankcardService.deleteUserBankcardByIds(ids));
	}
	
}
